package foroweb.ejb;

import java.util.Properties;
import javax.ejb.*;
import javax.mail.*;
import javax.mail.internet.*;

@Stateless
@Asynchronous
@LocalBean
public class Correo {

    //Metodos
    public void enviar(String destinatario,String asunto,String texto){
        Properties props=new Properties();
        props.setProperty("mail.smtp.host","smtp.gmail.com");
        props.setProperty("mail.smtp.starttls.enable","true");
        props.setProperty("mail.smtp.port","587");
        props.setProperty("mail.smtp.auth","true");

        Session session=Session.getDefaultInstance(props);

        MimeMessage message=new MimeMessage(session);
        try{
            message.addRecipient(Message.RecipientType.TO,new InternetAddress(destinatario));
            message.setSubject(asunto);
            message.setText(texto);

            Transport t=session.getTransport("smtp");
            t.connect("foroweb2dai@gmail.com","entornos");
            t.sendMessage(message,message.getAllRecipients());
            t.close();
        }catch(MessagingException me){
        }
    }
}
